package com.daoImpl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.dao.DeptmentDao;
import com.model.Deptment;

@Component("deptDao")
public class DeptmentDaoImpl implements DeptmentDao{
	private HibernateTemplate hibernateTemplate;
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public void addDept(Deptment dept) {
		hibernateTemplate.save(dept);
		
	}

	public void deleteDept(Deptment dept) {
		hibernateTemplate.delete(dept);
		
	}

	public boolean exists(Deptment dept) {
		List list=hibernateTemplate.find("from Deptment d where d.dt_name='"+dept.getDt_name()+"' ");
		if(list!=null&&list.size()>0){
			return true;
		}
		else return false;
	}

	public Deptment getDept(int id) {
		return (Deptment)this.hibernateTemplate.get(Deptment.class, id);
	}

	public List<Deptment> getDeptmentList(String hql) {
		List<Deptment> deptList=hibernateTemplate.find(hql);
		return deptList;
	}

	public void updateDept(Deptment dept) {
		hibernateTemplate.update(dept);
		
	}

}
